home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / eked-m1.zoo / src / comb_ed.c next >
C/C++ Source or Header  |  1995-02-19  |  8KB  |  280 lines

  1. /*
  2.  *  EKED-M1 : Editor for Korg M1 synth; comb_ed.c : combination editor
  3.  *  Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stddef.h>
  21. #include <string.h>
  22. #include <gemfast.h>
  23. #include <aesbind.h>
  24. #include "gm/gem_man.h"
  25. #include "eked-m1.h"
  26. #include "defs.h"
  27. #include "types.h"
  28. #include "externs.h"
  29.  
  30. typedef struct {
  31.   int offset;
  32.   PARA_TYPE type;
  33.   int page;
  34. } CPARAMETER;
  35.  
  36. CPARAMETER comb_table[] =
  37. {
  38.   {0,    PROG,    1},
  39.   {10,    CHAN,    2},
  40.   {6,    NOTE,    4},
  41.   {5,    NOTE,    3},
  42.   {8,    VEL,    6},
  43.   {7,    VEL,    5},
  44.   {1,    UNUM,    7},
  45.   {2,    SN12,    8},
  46.   {3,    SN50,    9},
  47.   {4,    CPAN,    10},
  48.   {9,    DIS0,    11},
  49.   {9,    DIS1,    12},
  50.   {9,    DIS2,    13},
  51.   {9,    DIS3,    14}
  52. };
  53.  
  54. static OBJECT *combination;
  55. static OBJECT *effect_route;
  56. static OBJECT *effect1;
  57. static OBJECT *effect2;
  58.  
  59. static BANK *edit_bank;
  60. static int number;
  61. static int in_use;
  62. static BYTE data[COMBINATION_SIZE];
  63. static BYTE compare[COMBINATION_SIZE];
  64.  
  65. static void comb_setup();
  66. static void display(int x_pos, int y_pos, GRECT *clip, long usr_val);
  67. static int action(int handle, E_TYPE type, void *event,
  68.                   int x_pos, int y_pos, long usr_val);
  69. static void save_comb(BYTE *p);
  70. static void do_click(int handle, int m_x, int m_y);
  71. static void setup(int x_pos, int y_pos);
  72. static void comb_edit(int handle, int m_x, int m_y);
  73. static void comb_buttons(int handle, int ob);
  74.  
  75. void ce_window(BANK *bank, int nr)
  76. {
  77.   static char title[] = "Edit Bank 0 Combination 00";
  78.   int t;
  79.  
  80.   if(in_use){
  81.     fm_alert(1, COMB_ED_ALERT);
  82.     return;
  83.   }
  84.   rm_gaddr(R_TREE, COMBINATION, &combination);
  85.   rm_gaddr(R_TREE, EFFECT_ROUTE_C, &effect_route);
  86.   rm_gaddr(R_TREE, EFFECT1_C, &effect1);
  87.   rm_gaddr(R_TREE, EFFECT2_C, &effect2);
  88.   edit_bank = bank;
  89.   number = nr;
  90.   memcpy(data, COMB_DATA(bank, nr), (size_t) COMBINATION_SIZE);
  91.   comb_setup();
  92.   combination[C_COMPARE].ob_state &= ~SELECTED;
  93.   combination[C_RESET].ob_state &= ~DISABLED;
  94.   combination[C_SAVE].ob_state &= ~DISABLED;
  95.   title[10] = '0' + bank->bank_nr;
  96.   title[sizeof(title) - 3] = '0' + nr / 10;
  97.   title[sizeof(title) - 2] = '0' + nr % 10;
  98.   t = wm_open(NAME | CLOSER | FULLER | MOVER | SIZER |
  99.               UPARROW | DNARROW | VSLIDE |
  100.               LFARROW | RTARROW | HSLIDE,
  101.               (GRECT *) 0, title, combination[0].ob_width,
  102.               combination[0].ob_height + effect_route[0].ob_height +
  103.               effect1[0].ob_height, char_w, char_h, &display, &action, 0L);
  104.   if(t < 0){
  105.     fm_alert(1, WINDOW_ALERT);
  106.     return;
  107.   }
  108.   in_use = TRUE;
  109. }
  110.  
  111. static void comb_setup()
  112. {
  113.   OBJECT *c;
  114.   BYTE *p;
  115.   int i, j;
  116.   
  117.   para_fill(combination + C_NAME, NM10, data);
  118.   c = combination + C_TIMBRE1 + 1;
  119.   for(i = 0, p = data + 36; i <= 7; i++, p += 11, c++){
  120.     for(j = 0; j < 14; j++, c++)
  121.       para_fill(c, comb_table[j].type, p + comb_table[j].offset);
  122.   }
  123.   eroute_setup(effect_route, data + 11);
  124.   epara_setup(effect1, 0, data + 11);
  125.   epara_setup(effect2, 1, data + 11);
  126. }
  127.  
  128. static void display(int x_pos, int y_pos, GRECT *clip, long usr_val)
  129. {
  130.   setup(x_pos, y_pos);
  131.   objc_draw(combination, 0, MAX_DEPTH, clip->g_x, clip->g_y,
  132.             clip->g_w, clip->g_h);
  133.   objc_draw(effect_route, 0, MAX_DEPTH, clip->g_x, clip->g_y, clip->g_w,
  134.             clip->g_h);
  135.   objc_draw(effect1, 0, MAX_DEPTH, clip->g_x, clip->g_y, clip->g_w, clip->g_h);
  136.   objc_draw(effect2, 0, MAX_DEPTH, clip->g_x, clip->g_y, clip->g_w, clip->g_h);
  137. }
  138.  
  139. static int action(int handle, E_TYPE type, void *event,
  140.                   int x_pos, int y_pos, long usr_val)
  141. {
  142.   BYTE *p;
  143.  
  144.   switch(type){
  145.   case E_CLEANUP:
  146.     m1_ctrl(handle, EXITING, 0, 0, (BYTE *) NULL);
  147.     in_use = FALSE;
  148.     break;
  149.   case E_MESSAGE:
  150.     if(((int *) event)[0] == WM_CLOSED){
  151.       p = (combination[C_COMPARE].ob_state & SELECTED) ? compare : data;
  152.       if(memcmp(p, COMB_DATA(edit_bank, number),
  153.                 (size_t) COMBINATION_SIZE) != 0){
  154.         switch(fm_alert(1, COMB_QUIT_ALERT)){
  155.         case 1:    /* save */
  156.           save_comb(p);
  157.           break;
  158.         case 3:    /* cancel */
  159.           return R_NOACT;
  160.         }
  161.       }
  162.     }
  163.     break;
  164.   case E_CLICK:
  165.     m1_ctrl(handle, 0, EDIT_COMB_MODE, number, data);
  166.     setup(x_pos, y_pos);
  167.     do_click(handle, ((CLICK *) event)->m_x, ((CLICK *) event)->m_y);
  168.     break;
  169.   }
  170.   return R_NORMAL;
  171. }
  172.  
  173. static void save_comb(BYTE *p)
  174. {
  175.   static int msg[] = {UPDATE_ITEM, 0};
  176.  
  177.   memcpy(COMB_DATA(edit_bank, number), p, (size_t) COMBINATION_SIZE);
  178.   if(edit_bank->comb_win != 0){
  179.     msg[1] = number;
  180.     wm_send_user(edit_bank->comb_win, (long) &msg);
  181.   }
  182. }
  183.  
  184. static void do_click(int handle, int m_x, int m_y)
  185. {
  186.   if(m_y < effect_route[0].ob_y)
  187.     comb_edit(handle, m_x, m_y);
  188.   else if(m_y < effect1[0].ob_y)
  189.     eroute_edit(handle, effect_route, 15, m_x, m_y, data + 11);
  190.   else if(m_x < effect2[0].ob_y)
  191.     effect_edit(handle, effect1, 0, 15, m_x, m_y, data + 11);
  192.   else
  193.     effect_edit(handle, effect2, 1, 15, m_x, m_y, data + 11);
  194. }
  195.  
  196. static void setup(int x_pos, int y_pos)
  197. {
  198.   int y1 = y_pos + combination[0].ob_height;
  199.   int y2 = y1 + effect_route[0].ob_height;
  200.  
  201.   combination[0].ob_x = x_pos;
  202.   combination[0].ob_y = y_pos;
  203.   effect_route[0].ob_x = x_pos;
  204.   effect_route[0].ob_y = y1;
  205.   effect1[0].ob_x = x_pos;
  206.   effect1[0].ob_y = y2;
  207.   effect2[0].ob_x = x_pos + effect1[0].ob_width;
  208.   effect2[0].ob_y = y2;
  209. }
  210.  
  211. static void comb_edit(int handle, int m_x, int m_y)
  212. {
  213.   int ob = objc_find(combination, 0, MAX_DEPTH, m_x, m_y);
  214.   int i, t;
  215.  
  216.   if(ob == C_NAME)
  217.     para_edit(handle, combination, ob, NM10, -1, -1, data);
  218.   else if(ob > C_TIMBRE1){
  219.     i = (ob - C_TIMBRE1 - 1) % 15;
  220.     t = (ob - C_TIMBRE1 - 1) / 15;
  221.     if(i <= 13 && t <= 7){
  222.       para_edit(handle, combination, ob, comb_table[i].type,
  223.                 comb_table[i].page, t + 8,
  224.                 data + 36 + 11 * t + comb_table[i].offset);
  225.     }
  226.   }
  227.   else
  228.     comb_buttons(handle, ob);
  229. }
  230.  
  231. static void comb_buttons(int handle, int ob)
  232. {
  233.   switch(ob){
  234.   case C_COMPARE:
  235.     if(!wm_do_button(handle, combination, ob, TRUE))
  236.       return;
  237.     if(combination[C_COMPARE].ob_state & SELECTED){
  238.       memcpy(compare, data, (size_t) COMBINATION_SIZE);
  239.       memcpy(data, COMB_DATA(edit_bank, number), (size_t) COMBINATION_SIZE);
  240.     }
  241.     else
  242.       memcpy(data, compare, (size_t) COMBINATION_SIZE);
  243.     combination[C_RESET].ob_state ^= DISABLED;
  244.     combination[C_SAVE].ob_state ^= DISABLED;
  245.     break;
  246.   case C_RESET:
  247.     if(!wm_do_button(handle, combination, ob, FALSE))
  248.       return;
  249.     memcpy(data, COMB_DATA(edit_bank, number), (size_t) COMBINATION_SIZE);
  250.     break;
  251.   case C_SAVE:
  252.     if(wm_do_button(handle, combination, ob, FALSE))
  253.       save_comb(data);
  254.     return;
  255.   default:
  256.     return;
  257.   }
  258.   tx_comb_dmp(data);
  259.   comb_setup();
  260.   wm_update(handle);
  261. }
  262.  
  263. void prog_update(OBJECT *object, int value)
  264. {
  265.   char *string = TEXT_PTR(object, 0);
  266.  
  267.   if(value == -1){
  268.     (void) strcpy(string, "OFF       ");
  269.     return;
  270.   }
  271.   if(value < 100)
  272.     (void) korg2str(string, PROG_DATA(edit_bank, value), (size_t) 10);
  273.   else{
  274.     value -= 100;
  275.     (void) strcpy(string, "Card      ");
  276.     string[5] = '0' + value / 10;
  277.     string[6] = '0' + value % 10;
  278.   }
  279. }
  280.